﻿using Common;
using MVP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinForms
{
    public partial class PeriodSemester : Form, IPeriodSemesterView
    {
        private PeriodSemesterPresenter _presenter;

        public PeriodSemester()
        {
            _presenter = new PeriodSemesterPresenter(this);
            InitializeComponent();
            InvokeInitialize(new EventArgs());
        }

        #region IPeriodSemesterView Members

        public IList<string> Semesters
        {
            set { semesterComboBox.DataSource = value; }
        }

        public EnumSemester SelectedSemester
        {
            get { return Enums.GetSemesterByName(semesterComboBox.SelectedItem.ToString()); }
        }

        public int Year
        {
            get
            {
                return (int)tahunNumericUpDown.Value;
            }
            set
            {
                tahunNumericUpDown.Value = value;
            }
        }
        public event EventHandler Initialize;
        #endregion

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
        }

        public void InvokeInitialize(EventArgs e)
        {
            EventHandler handler = Initialize;
            if (handler != null)
            {
                handler(this, e);
            }
        }

    }

    public static class SelectPeriodSemesterBox
    {
        public static String[] Show()
        {
            PeriodSemester periodSemester = new PeriodSemester();
            if (periodSemester.ShowDialog() == DialogResult.OK)
            {
                return new String[] { periodSemester.SelectedSemester.ToString(), periodSemester.Year.ToString() };
            }

            return null;
        }
    }
}
